package com.ejuornal.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.AdsPos;
import com.ejuornal.bean.User;
import com.ejuornal.service.AdsPosService;
import com.ejuornal.springutil.SpringUtil;
import com.google.gson.Gson;

@Component("adsPosAction")
@Scope("prototype")
public class AdsPosAction extends BaseAction<User> {
	private static final long serialVersionUID = 1L;
	private AdsPosService  adsPosService=null;
	private String adsPosList = null;
	private AdsPos adsPos = null;
	/**
	 * 描述：获取所有的广告位置的List列表
	 * 作者：lwf
	 * @return List<AdsPos>
	 */
	public String getAllAdsPos(){
		adsPosService = (AdsPosService) SpringUtil.getBean("adsPosService");
		List<AdsPos> list = adsPosService.findAllList();
		Gson gson = new Gson();
		adsPosList = gson.toJson(list);
		HttpServletResponse res = ServletActionContext.getResponse();   
		res.reset();   
		res.setContentType("text/html;charset=utf-8");   
		PrintWriter pw;
		try {
			pw = res.getWriter();
			pw.print(adsPosList);
			pw.flush();   
			pw.close();  
		} catch (IOException e) {
			e.printStackTrace();
		}   
		return "allAdsPosList";
	}
	
	
	public AdsPos getAdsPos() {
		return adsPos;
	}

	public void setAdsPos(AdsPos adsPos) {
		this.adsPos = adsPos;
	}


	public String getAdsPosList() {
		return adsPosList;
	}


	public void setAdsPosList(String adsPosList) {
		this.adsPosList = adsPosList;
	}


	public AdsPosService getAdsPosService() {
		return adsPosService;
	}
	@Resource(name="adsPosService")
	public void setAdsPosService(AdsPosService adsPosService) {
		this.adsPosService = adsPosService;
	}
}
